package com.rgs.module.login.bo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Map;

/**
 * @author Ren Gaoshuai
 * @ClassName LoginUserBO
 * @date 2021-12-24 16:14
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class LoginUserBO implements UserDetails {


    /**
     * 登录时间
     */
    private LocalDateTime loginDateTime;

    private String userId;
    private String username;
    private String password;

    private Boolean isAdmin;
    private Map<String, Object> otherInfo;
    /**
     * 指定用户是否解锁,锁定的用户无法进行身份验证
     *
     * @return
     */
    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 账户是否未过期,过期无法验证
     */
    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
     *
     * @return
     */
    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return true;
    }

    Collection<? extends GrantedAuthority> authorities;

}
